package br.com.californiahotel.client.viewControler.apartamento;

import br.com.californiahotel.client.architecture.viewController.BasicView;
import br.com.californiahotel.client.viewControler.apartamento.ApartamentoFormController.Display;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.ComboBoxItem;
import com.smartgwt.client.widgets.form.fields.SpacerItem;
import com.smartgwt.client.widgets.form.fields.TextItem;

public class ApartamentoFormView extends BasicView implements Display {

	public enum Field{
		NRO_APTO("nro_apto"),TYPE("tipo"),SAVE("PasswordField"),CANCEL("cancel");

		private final String fieldName;

		private Field(String name) {
			fieldName = name;
		}

		public String getFieldName() {
			return fieldName;
		}

	}

	private DynamicForm form;

	public ApartamentoFormView() {
		mountForm();
		setAutoWidth();
		setHeight100();
		setMargin(20);
	}

	public ApartamentoFormView(Long cdApartamento, String nro_apto, Double value) {
		mountForm();
		setAutoWidth();
		setHeight100();
		setMargin(20);
		form.getItem(Field.NRO_APTO.getFieldName()).setValue(nro_apto);
		//		form.getItem(Field.VALUE.getFieldName()).setValue(value);
	}

	private void mountForm() {
		form = new DynamicForm();
		form.setShowEdges(true);
		form.setNumCols(10);

		TextItem numeroAptoTextItem = new TextItem(Field.NRO_APTO.getFieldName(), "Numero do Quarto");
		numeroAptoTextItem.setKeyPressFilter("[0-9]");
		numeroAptoTextItem.setColSpan(10);

		ComboBoxItem typeComboBoxItem = new ComboBoxItem(Field.TYPE.getFieldName(), "Tipo");
		typeComboBoxItem.setStartRow(true);
		typeComboBoxItem.setEndRow(true);
		typeComboBoxItem.setColSpan(10);
		typeComboBoxItem.setTextAlign(Alignment.CENTER);

		ButtonItem cancelButtonItem = new ButtonItem(Field.CANCEL.getFieldName(), "Cancelar");
		cancelButtonItem.setAlign(Alignment.RIGHT);
		cancelButtonItem.setAutoFit(true);
		cancelButtonItem.setStartRow(false);
		cancelButtonItem.setEndRow(false);

		ButtonItem saveButtonItem = new ButtonItem(Field.SAVE.getFieldName(), "Salvar");
		saveButtonItem.setAlign(Alignment.RIGHT);
		saveButtonItem.setAutoFit(true);
		saveButtonItem.setEndRow(false);
		saveButtonItem.setStartRow(false);
		saveButtonItem.setDisabled(true);

		form.setCellPadding(5);
		form.setFields( numeroAptoTextItem, typeComboBoxItem, new SpacerItem(), new SpacerItem(), cancelButtonItem, saveButtonItem);
		addChild(form);

	}

	@Override
	public DynamicForm getForm() {
		return form;
	}

}
